// src/views/your-view-folder/columns.ts

import { h } from 'vue';
import { NAvatar, NTag } from 'naive-ui';
import { BasicColumn } from '@/components/Table';
import type { UserItem } from '@/api/system/user';

/**
 * @description: 性别文本映射 (使用布尔值作为 key)
 */
const genderMap = {
  true: '男',
  false: '女',
};

/**
 * @description: 状态文本和标签类型映射
 */
const statusMap = {
  1: { text: '正常', type: 'success' },
  2: { text: '封禁', type: 'error' },
  3: { text: '已注销', type: 'default' },
};

export const columns: BasicColumn<UserItem>[] = [
  {
    title: 'ID',
    key: 'userId',
    align:'center',
    width: 80,
  },
  {
    title: '用户昵称',
    key: 'nickname',
    align:'center',
    width: 150,
  },
  {
    title: '头像',
    key: 'avatar',
    align:'center',
    width: 80,
    render(record) {
      return h(NAvatar, {
        size: 'medium',
        src: record.avatar,
        fallback: record.nickname?.[0] || 'U',
      });
    },
  },
  {
    title: '性别',
    key: 'gender',
    align:'center',
    width: 80,
    render(record) {
      // 🌟 根据布尔值获取性别文本和标签类型
      const genderText = genderMap[record.gender] || '未知';
      return h(
        NTag,
        {
          type: record.gender ? 'info' : 'success', // 🌟 true(男): 'info', false(女): 'success'
        },
        {
          default: () => genderText,
        }
      );
    },
  },
  {
    title: '手机号',
    key: 'phone',
    align:'center',
    width: 140,
  },
  {
    title: '状态',
    key: 'status',
    align:'center',
    width: 100,
    render(record) {
      const statusInfo = statusMap[record.status] || { text: '未知', type: 'warning' };
      return h(
        NTag,
        {
          type: statusInfo.type,
        },
        {
          default: () => statusInfo.text,
        }
      );
    },
  },
  {
    title: '注册时间',
    key: 'registerTime',
    align:'center',
    width: 180,
  },
];
